package com.edu.exam.enums.grading;

import com.edu.exam.enums.core.StatusEnum;

/**
 * 草稿状态枚举
 */
public enum DraftStatus implements StatusEnum {
    /**
     * 活跃状态
     */
    ACTIVE("ACTIVE", "活跃", 1),
    
    /**
     * 编辑中状态
     */
    EDITING("EDITING", "编辑中", 2),
    
    /**
     * 提交中状态
     */
    SUBMITTING("SUBMITTING", "提交中", 3),
    
    /**
     * 已提交状态
     */
    SUBMITTED("SUBMITTED", "已提交", 4),
    
    /**
     * 失败状态
     */
    FAILED("FAILED", "失败", 5),
    
    /**
     * 已过期状态
     */
    EXPIRED("EXPIRED", "已过期", 6),
    
    /**
     * 已删除状态
     */
    DELETED("DELETED", "已删除", 7);

    private final String code;
    private final String description;
    private final int order;

    DraftStatus(String code, String description, int order) {
        this.code = code;
        this.description = description;
        this.order = order;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public int getOrder() {
        return order;
    }

    /**
     * 根据编码查找枚举值
     */
    public static DraftStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return ACTIVE;
        }

        for (DraftStatus value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return ACTIVE;
    }

    /**
     * 根据描述查找枚举值
     */
    public static DraftStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (DraftStatus value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}